﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using COFE.Core;
using COFE.Core.Profile;
using COFE.Core.Utils;
using COFE.Core.Filter;

namespace COFE.Core.Lister
{
    public abstract class DirectoryListerBase : IDirectoryLister
    {
        #region Constructor

        public DirectoryListerBase(IFactory<IDirectoryLister> factory, string listerKey)
        {
            _factory = factory;
            ListerKey = listerKey;
        }

        #endregion

        #region Methods        

        /// <summary>
        /// Return a list of subentries
        /// </summary>
        /// <param name="parent">Parent of the entries.</param>
        /// <param name="filters">Return if one of the filters return true on match.</param>
        /// <returns></returns>
        public virtual IEnumerable<IFileSystemInfo> List(IInternalDirectoryInfoExA parent, EntryConstructionFlags flags)
        {
            return _list(parent, flags);
        }

        public virtual IInternalDirectoryInfoExA GetParent(IInternalFileSystemInfoExA entry)
        {
            return _getParent(entry);
        }

        public virtual void Expand(IInternalFileSystemInfoExA entry)
        {
            _expand(entry, entry.TempPath);
        }

        public virtual int GetPosition(IInternalFileSystemInfoExA entry)
        {
            return _getPosition(entry);
        }

        public virtual void SetPosition(IInternalFileSystemInfoExA entry, int position)
        {
            _setPosition(entry, position);
        }

        public abstract IDirectoryController CreateController();

        public abstract IStreamProvider CreateStreamProvider();

        #endregion

        #region Data
        private IFactory<IDirectoryLister> _factory = null;

        protected Func<IDirectoryInfo, EntryConstructionFlags, IEnumerable<IFileSystemInfo>> _list = (item, flags) => { return new List<IFileSystemInfo>(); };
        protected Func<IFileSystemInfo, IInternalDirectoryInfoExA> _getParent = (item) => { return null; };

        protected Action<IFileSystemInfo, string> _expand = (item, tempPath) => { };
        protected Func<IFileSystemInfo, int> _getPosition = (item) => { return -1; };
        protected Action<IFileSystemInfo, int> _setPosition = (item, pos) => { };


        #endregion

        #region Public Properties

        public string ListerKey { get; set; }
        public IFactory<IDirectoryLister> Factory { get { return _factory; } }

        #endregion


      
    }
}
